﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Management.Automation;
using PowerOBIProvider;
using System.Collections.ObjectModel;
using PowerOBIProvider.OBI;
using PowerOBIPRovider.OBIWebReference;

namespace PowerOBIProvider.Cmdlts
{
    [Cmdlet(VerbsCommon.Get,"SubjectArea")]
    
    public class GetSubjectAreaCmdlt :BaseOBICmdlt
    {
        private string drive = null;
        [Parameter(Mandatory = false, Position = 1)]
        [ValidateNotNullOrEmpty]
        public string Drive
        {
            get
            {
                return drive;
            }
            set
            {
                drive = value;
            }
        }
        protected override void ProcessRecord()
        {
            PSOBIDriveInfo obiDrive = null;
            if (drive == null)
            {
                obiDrive = GetOBIDrive(SessionState.Path.CurrentLocation);
            }
            else
            {
                obiDrive = SessionState.Drive.Get(drive) as PSOBIDriveInfo;
            }
            try
            {
                SASubjectArea[] subjectAreas =  obiDrive.ObiWSClient.GetSubjectAreas();
                foreach (SASubjectArea sa in subjectAreas)
                {
                    WriteObject(sa);
                }
                
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "0", ErrorCategory.OperationStopped, null));
            }
        }
    }
}
